package com.xuecheng.content.controller;

import com.xuecheng.content.service.CoursePubService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * <p>
 * 课程发布前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
@RequestMapping("/coursePub")
public class CoursePubController {

    @Autowired
    private CoursePubService coursePubService;

    @GetMapping("/preview/{courseBaseId}")
    public ModelAndView preview(@PathVariable("courseBaseId") Long courseBaseId) {
        //创建视图与模型对象
        ModelAndView mv = new ModelAndView();
        //指定模板
        mv.setViewName("learing_article");
        //指定数据
        Map map = coursePubService.preview(courseBaseId);
        mv.addAllObjects(map);
        //返回
        return mv;
    }
}
